﻿using mfRCF.Core.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections;

namespace mfRCF.Core.Test
{
    
    
    /// <summary>
    ///This is a test class for mfGETParameterSplitterTest and is intended
    ///to contain all mfGETParameterSplitterTest Unit Tests
    ///</summary>
    [TestClass()]
    public class mfGETParameterSplitterTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for ExtractUrlParameter, with string.empty
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(mfRcfException))]
        public void ExtractUrlParameterTest_Invalid_EmptyString()
        {
            string relativeGetString = string.Empty; 
            mfStringExtensions.ExtractUrlParameter(relativeGetString);
        }

        /// <summary>
        ///A test for ExtractUrlParameter, with string = null
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(mfRcfException))]
        public void ExtractUrlParameterTest_Invalid_NullString()
        {
            string relativeGetString = null;
            mfStringExtensions.ExtractUrlParameter(relativeGetString);
        } 

        /// <summary>
        ///A test for ExtractUrlParameter
        ///</summary>
        [TestMethod()]
        public void ExtractUrlParameterTest_Valid_relativeUrl()
        {
            string relativeGetString = "rss?name=asdf&date=01.01.2014";
            Hashtable actual;
            actual = mfStringExtensions.ExtractUrlParameter(relativeGetString);

            Assert.AreEqual("asdf", actual["name"]);
            Assert.AreEqual("01.01.2014", actual["date"]);
        }        
        
        /// <summary>
        ///A test for ExtractUrlParameter
        ///</summary>
        [TestMethod()]
        public void ExtractUrlParameterTest_Valid_absoluteUrlWithPort()
        {
            string relativeGetString = "http://localhost:123/rss?name=asdf&date=01.01.2014";
            Hashtable actual;
            actual = mfStringExtensions.ExtractUrlParameter(relativeGetString);

            Assert.AreEqual("asdf", actual["name"]);
            Assert.AreEqual("01.01.2014", actual["date"]);
        }

        /// <summary>
        ///A test for ExtractUrlParameter
        ///</summary>
        [TestMethod()]
        public void ExtractBaseUrl_Valid_absoluteUrlWithPort()
        {
            string relativeGetString = "http://localhost:123/rss?name=asdf&date=01.01.2014";
            String actual;
            actual = mfStringExtensions.ExtractBaseUrl(relativeGetString);

            Assert.AreEqual("http://localhost:123/rss", actual);
        }
    }
}
